//
//  HZHomeModel.swift
//  weibo002
//
//  Created by 黑眼圈 on 16/4/20.
//  Copyright © 2016年 heiyan. All rights reserved.
//

import UIKit

class HZHomeModel: NSObject {
    
    //正文本
    var text:String?
    //时间
    var created_at:String?
    //来源
    var source:String?
    
    //配图的数组
    var pic_urls:[HZImageModel]?
    
    /// 微博的用户信息
    var user: HZHomeOwnModel?
    
    
    /// 转发微博
    var retweeted_status: HZHomeModel?
    
    //最后一个 cell 的 id编号
    var id:Int64 = 0
    
    
    // MARK: - kvc构造方法
    init(dict:[String:AnyObject]) {
        
        super.init()
        
        setValuesForKeysWithDictionary(dict)
    }
    
    override func setValue(value: AnyObject?, forKey key: String) {
        
        //如果是深一层的字典就再装换一次
        if key == "user" {
            
            guard let dict = value as? [String: AnyObject] else{
                return
            }
            
            user = HZHomeOwnModel(dict: dict)
            
            
            //如果是转载的微博,再进行一次字典转模型
        }else if key == "retweeted_status" {
            
            guard let dict = value as? [String:AnyObject] else {
                return
            }
            
            retweeted_status = HZHomeModel(dict: dict)
            
            //如果是配图的数组
        }else if key == "pic_urls" {
            
            guard let dictArr = value as? [[String:AnyObject]] else{
                return
            }
            
            //遍历 转模型
            var arrM = [HZImageModel]()
            
            for value in dictArr {
                
                let img = HZImageModel(dict: value)
                
                arrM.append(img)
            }
            pic_urls = arrM
            
        }else{
            
            super.setValue(value, forKey: key)
        }
        
        
    }
    
    
    //防止KVC赋值出错
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {
        
    }
    
    

}
